<?php
/**
 * User: Drery
 * Date: 2015/12/25
 * Time: 16:18
 */

namespace backend\components\grid;

use Yii;
use yii\grid\ActionColumn;
use yii\helpers\Html;

class MyActionColumn extends ActionColumn
{
    public $header = '操作';
    /**
     *  Initializes the default button rendering callbacks.
     */
    protected function initDefaultButtons()
    {
        $this->template = Html::tag('div',$this->template,['class'=>'btn-group']);
        if (!isset($this->buttons['update'])) {
            $this->buttons['update'] = function ($url, $model, $key) {
                $options = array_merge([
                    'class' => 'btn btn-success btn-sm',
                    'data-pjax' => '0',
                ], $this->buttonOptions);
                return Html::a(Yii::t('yii','Update'), $url, $options);
            };
        }
        if (!isset($this->buttons['delete'])) {
            $this->buttons['delete'] = function ($url, $model, $key) {
                $options = array_merge([
                    'class' => 'btn btn-danger btn-sm',
                    'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                    'data-method' => 'post',
                    'data-pjax' => '0',
                ], $this->buttonOptions);
                return Html::a(Yii::t('yii','Delete'), $url, $options);
            };
        }
    }
}